package com.xmy.cultivate.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmy.cultivate.entity.EnrollStagePeriod;
import com.xmy.cultivate.entity.EnrollStageType;
import com.xmy.cultivate.service.IEnrollStageTypeService;
import com.xmy.cultivate.util.Code;
import com.xmy.cultivate.util.PageResult;
import com.xmy.cultivate.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.Map;

/**
 * <p>
 * 招生阶段名称 前端控制器
 * </p>
 *
 * @author hpiggy
 * @since 2024-09-04
 */
@RestController
@RequestMapping("/api/enrollStageType")
public class EnrollStageTypeController {
    @Autowired
    IEnrollStageTypeService iEnrollStageTypeService;

    @GetMapping()
    public Result getEnrollStageType(@RequestParam Map reMap) {
        Integer pageNum = StringUtils.isEmpty((String) reMap.get("pageNum")) ? 1 : Integer.valueOf((String) reMap.get("pageNum"));
        Integer pageSize = StringUtils.isEmpty((String) reMap.get("pageSize")) ? 10 : Integer.valueOf((String) reMap.get("pageSize"));
        IPage<EnrollStageType> iPage = new Page<>(pageNum, pageSize);

        iEnrollStageTypeService.page(iPage);

        return new Result(Code.OK, new PageResult(iPage.getRecords(), iPage.getTotal(), iPage.getPages()), Code.GET_OK_MSG);
    }

    @PostMapping()
    public Result saveEnrollStageType(@RequestBody EnrollStageType enrollStageType) {
        iEnrollStageTypeService.saveOrUpdate(enrollStageType);
        return new Result(Code.OK,"", Code.GET_OK_MSG);
    }

}
